package ink.lovejinhu.leetcode;

/**
 * @author jinhu
 * created 2021-07-06 17:14
 */
public class Solution_0204 {
    /**
     * 统计小于n的质数
     *
     * @param n
     * @return
     */
    public int countPrimes(int n) {
        if (n < 2) return 0;
        int count = 0;
        for (int i = 2; i <n; i++) {
            if (this.isZhiShu(i)){
                count++;
            }
        }
        return count;
    }

    public boolean isZhiShu(int x) {
        if (x < 2) return false;
        for (int i = 2; i <= x / i; i++)
            if (x % i == 0)
                return false;
        return true;
    }
}
